package middleware

import (
	"errors"
	"fmt"
	"haiqiu-go-admin/result"
	"net/http"
)

func Method(s string) Middleware {
	return func(handlerFunc http.HandlerFunc) http.HandlerFunc {
		return func(w http.ResponseWriter, r *http.Request) {
			if r.Method != s && r.Method != http.MethodOptions {
				result.Fail(w, r, errors.New(fmt.Sprintf("该接口不支持%v请求方式", r.Method)))
				return
			}
			handlerFunc(w, r)
		}
	}
}
